package com.wu01.demo.controller;

import com.wu01.demo.Entity.Emp;
import com.wu01.demo.Entity.User;
import com.wu01.demo.mapper.UserMapper;
import com.wu01.demo.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//@RestController
@Controller
public class UserController {
//    @Autowired
//    UserService userService;
    @Autowired
    EmpService empService;

//    @RequestMapping("/user/{id}")
//    public User getUser(@PathVariable("id") Integer id){
//        return userService.getUserById(id);
//    }
//
//    @RequestMapping("/user")
//    public User getUser(User user){
//        return userService.updateUser(user);
//    }
//    @RequestMapping("/login_page")
//    public User delUser(User user){
//        return userService.deleteUser(user);
//    }

    @RequestMapping(value = "/user/{id}/name/{name1}",method = RequestMethod.GET)
    public Map<String,Object> getUser(@PathVariable("id") String idd, @PathVariable("name1") String name2,
                                      @PathVariable Map<String,Object> mv,
                                      @RequestHeader("User-Agent") String agent,
                                      @RequestHeader Map<String,Object> heads,
                                      @RequestParam("age") String age,
                                      @RequestParam("inters") List<String> intersList,
                                      @RequestParam Map<String,Object> map11,
                                      @CookieValue Cookie cookie){
        Map<String,Object> map = new HashMap<>();
        map.put("age",age);
        map.put("inters",intersList);
        map.put("map",map11);
        System.out.println(cookie);
//        map.put("cookie",cookie);
//        map.put("id",idd);
//        map.put("name",name2);
//        map.put("pv",mv);
//        map.put("agent",agent);
//        map.put("heads",heads);
        return map;


//        System.out.println("get");
    }
    @RequestMapping(value = "/user",method = RequestMethod.POST)
    public void postUser(User user,@RequestBody String body){
        System.out.println(body);
        System.out.println("post"+user);
    }
    @RequestMapping(value = "/user",method = RequestMethod.DELETE)
    public void delUser(User user){
        System.out.println("del");
    }

    @RequestMapping(value = "/user",method = RequestMethod.PUT)
    public void putUser(User user){
        System.out.println("put");
    }

    @RequestMapping("/goto")
    public String gotopage(HttpServletRequest request){
        request.setAttribute("msg","success");
        request.setAttribute("code",200);
        return "forward:/success";
    }

    @ResponseBody
    @RequestMapping("/success")
    public Map<String,Object> success(@RequestAttribute("msg") String msg1,
                       @RequestAttribute("code") String code,
                       HttpServletRequest request){
        Object msg2 = request.getAttribute("msg");
        Map<String,Object> map = new HashMap<>();
        map.put("reqMethod_msg",msg2);
        map.put("annotation_msg",msg1);
        return map;
    }

    @ResponseBody
    @GetMapping("/car/{path1}/{path2}")
    public Map carSell(@MatrixVariable(value = "age",pathVar = "path1") Integer age1,
                       @MatrixVariable(value = "age",pathVar = "path2") Integer age2
                       /*@PathVariable("path") String path*/){
        Map<String,Object> map = new HashMap<>();
        map.put("age1",age1);
        map.put("age2",age2);
        return map;
    }
//    @RequestMapping("/user")
//    public User insertUser(User user){
//        userMapper.insertUser(user);
//        System.out.println(user);
//        return user;
//    }

}
